<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all"/>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css"
      media="all"/>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/component.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/normalize.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.printPage.js"></script>
<script src="<?php echo URL::base() ?>media/js/jquery.form.js"></script>
<style>
    .table td, .table th {
        text-align: center;
    }

    .form-horizontal .control-label {
        width: 100px;
    }

    .form-horizontal .controls {
        margin-left: 110px;
    }

    a.xiazai:hover {
        text-decoration: none;
    }

    table tbody tr:nth-child(2n) {
        background-color: #f5f5f5;
    }

    .table th, .table td {
        border: 1px solid #ffffff;
    }

    .gy-navtent2-input label {
        width: 120px;
        text-align: right;
    }

    .gy-navtent2-input {
        margin-bottom: 10px;
    }

</style>

<script type="text/javascript">
    $(document).ready(function () {
        $('#table_content > tr:odd').css("background-color", "#f5f5f5");
    });

    $(function(){
        $('.dblclick_sku').dblclick(function(){
            var obj = $(this).parent().children("td").last().children("input");
            var sku = $(obj).eq(1).val();
            var in_id = $(obj).eq(2).val();
            var stock_old = $(obj).eq(3).val();
            var num = $(obj).eq(4).val();
            if (num != 1 && num != 3) {
                var dialog = art.dialog({title: 'SKU盘点修改', lock: true});
                dialog.content('<p>数据查询中,请稍后...<p>');
                $.get("<?php echo URL::base(true)?>checkstock/updatePandian",
                    {"sku": sku, "in_id": in_id, "stock_old": stock_old, 'num': num},
                    function (view) {
                        var obj = jQuery.parseJSON(view);
                        dialog.content(obj.view);
                    });
            }
        })
    });
</script>
<div class="gy-navtent2">
    <form class="form-inline" id="search_form">
        <div class="gy-navtent2-input">
            <label>库位：</label>

            <div class="input-append">
                <input class="span2" type="text" name="storage1"
                       value="<?php echo isset($get['storage1'])?$get['storage1']:''; ?>"
                       onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"/>
                <span class="add-on">0000</span>
            </div>
            <label style="width: auto">到</label>

            <div class="input-append">
                <input class="span2" type="text" name="storage2"
                       value="<?php echo isset($get['storage2'])?$get['storage2']:''; ?>"
                       onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"/>
                <span class="add-on">0000</span>
            </div>
            &nbsp;&nbsp;
            <label>库位搜索：</label>
            <input class="span2" type="text" placeholder="库位模糊搜索" name="storage"
                   value="<?php echo isset($get['storage'])?$get['storage']:''; ?>"/>
        </div>
        <div class="gy-navtent2-input">
            <label>SKU：</label>
            <input class="span2" type="text" name='sku' value="<?php echo isset($get['sku'])?$get['sku']:''; ?>"/>
            <label>排序条件：</label>
            <select class="form-control input-sm span2" name='sort'>
                <option value="1" <?php if(isset($get['sort'])&&$get['sort']==1){
                    echo "selected='selected'";
                } ?>>选择（默认销量）
                </option>
                <option value='2' <?php if(isset($get['sort'])&&$get['sort']==2){
                    echo "selected='selected'";
                } ?>>SKU
                </option>
                <option value='3' <?php if(isset($get['sort'])&&$get['sort']==3){
                    echo "selected='selected'";
                } ?>>储位
                </option>
            </select>
            <label>排序方式：</label>
            <select class="form-control input-sm span2" name='order'>
                <option value='1' <?php if(isset($get['order'])&&$get['order']==1){
                    echo "selected='selected'";
                } ?>>降序
                </option>
                <option value='2' <?php if(isset($get['order'])&&$get['order']==2){
                    echo "selected='selected'";
                } ?>>升序
                </option>
            </select>
        </div>
        <div class="gy-navtent2-input">
            <label>盘点情况：</label>
            <select class="form-control span2" name='status' id="status_id">
                <option value="" selected="selected">全部</option>
                <?php if(isset($status) and $status){
                    foreach($status as $status_id => $_status){
                        ?>
                        <option
                            value="<?php echo $status_id ?>" <?php if(isset($get['status'])&&$get['status']==$status_id){
                            echo "selected='selected'";
                        } ?>>
                            <?php echo $_status ?>
                        </option>
                    <?php
                    }
                } ?>
            </select>
            <label>盘点截止日期：</label>
            <input type="text" name='start_time' class=" datepicker span2" id="start" readonly="readonly"
                   value="<?php if(isset($get['start_time'])&&$get['start_time']){
                       echo $get['start_time']; }else{ echo date('Y-m-d'); }?>">
            <label>SKU来源：</label>
            <select class="form-control span2" name='source' id="source">
                <option value="1" <?php if(isset($get['source'])&&$get['source']==1){
                    echo "selected='selected'";
                } ?>>热销品</option>
                <option value="100" <?php if(isset($get['source'])&&$get['source']==100){
                    echo "selected='selected'";
                } ?>>低库存</option>
            </select>
            <input type="submit" class="btn btn-info" value="查询"/>
            <input type="reset" value="重置" class="btn btn-inverse" id="reset_"/>
        </div>
    </form>
</div>
<div>
    <div>
        <div>
            <label style="color: #ff0000">
                SKU更新日期为：<?php echo isset($record['add_time'])?$record['add_time']:0; ?>，
                共<?php echo isset($record['number'])?$record['number']:0; ?>个，
                已盘点<?php echo isset($nums[2]['num'])?$nums[2]['num']:0 ?>个，
                未盘点<b><?php echo isset($nums[1]['num'])?$nums[1]['num']:0 ?></b>个,
                需紧急盘点<?php echo isset($nums[3]['num'])?$nums[3]['num']:0 ?>个，
                已紧急盘点<?php echo isset($nums[4]['num'])?$nums[4]['num']:0 ?>个.
            </label>
            <table class="table table1 table-bordered" style="border-collapse: collapse;">
                <thead>
                <tr style="background-color:#4EA392;color:#fff; font-weight:bold;">
                    <th>排名</th>
                    <th>SKU</th>
                    <th>中文名称</th>
                    <th>储位</th>
                    <th>期初库存</th>
                    <th>本期入</th>
                    <th>本期出</th>
                    <th>库存量</th>
                    <th>借料备注量</th>
                    <th>销量</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id='table_content'>
                <?php
                if(isset($lists)){
                    foreach($lists as $list):?>
                        <tr>
                            <td><?php echo $first++; ?></td>
                            <td><?php echo $list['sku'] ?></td>
                            <td><?php echo $list['sku_name'] ?></td>
                            <td><?php echo $list['storage'] ?></td>
                            <td><?php echo $list['qichu'] ?></td>
                            <td><?php echo $list['benqiru'] ?></td>
                            <td><?php echo $list['benqichu'] ?></td>
                            <td><?php echo $list['quantity'] ?>  </td>
                            <td <?php if($list['lend']){?>style="color: red"><?php }echo $list['lend'];?></td>
                            <td><?php echo $list['sale'] ?>  </td>
                            <td class="dblclick_sku"><?php echo $status[$list['status']]; ?></td>
                            <td>
                                <?php if($list['status']==1){ ?>
                                    <input type="button" class="btn btn-info" onclick="check(this,2)" value="盘点"/>
                                <?php }elseif($list['status']==3){ ?>
                                    <input style="color: #ff0000" type="button" class="btn btn-danger"
                                           onclick="check(this,4)" value="紧急盘点"/>
                                <?php }elseif($list['status']==4){ ?>
                                    <input type="button" class="btn btn-success" value="紧急已盘点"/>
                                <?php }else{ ?>
                                    <input type="button" class="btn btn-success" value="已盘点"/>
                                <?php } ?>
                                <input type="hidden" value="<?php echo $list['sku']; ?>"/>
                                <input type="hidden" value="<?php echo $list['in_id']; ?>"/>
                                <input type="hidden" value="<?php echo $list['quantity'] ?>"/>
                                <input type="hidden" value="<?php echo $list['status'] ?>"/>
                            </td>
                        </tr>
                    <?php endforeach;
                } ?>
                <tr>
                    <td colspan="13">
                        <div><?php if(isset($page)){
                                echo $page;
                            } ?></div>
                    </td>
                </tr>
                </tbody>
            </table>
            <div id="pager_links"></div>
            <div class="btn btn-success" id='search_down'><a class="xiazai" style="color:#FFF;">查询结果下载</a></div>
            <div class="btn btn-success" id='down'><a class="xiazai" style="color:#FFF;">下载</a></div>(下载排名前5000中的未盘点SKU)
            <div class="gy-navtent2-input">
                <div>
                    <h2>库存盘点批量上传：</h2>

                    <form class="upSuppForm" method='post'
                          action='<?php echo URL::site() ?>checkstock/upload'
                          enctype="multipart/form-data">
                        <table class="table table-striped">
                            <tr>
                                <td class="need"></td>
                                <td>批量上传</td>
                                <td><input type='file' style="line-height: 0px;" name='xls' class="inputxt"
                                           datatype="/.+\.xls/" nullmsg="请选择上传文件" errormsg="文件格式只能为xls"/></td>
                                <td>
                                    <div class="Validform_checktip"></div>
                                </td>
                            </tr>
                            <tr>
                                <td class="need"></td>
                                <td></td>
                                <td colspan="2">

                                </td>
                            </tr>
                        </table>
                        <input type='submit' value='上传' class='btn btn-success' id="upload"/>
                    </form>

                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab_2">
        </div>
    </div>
</div>

<script type="text/javascript">
    //单个盘点
    function check(obj, num) {
        var sku = $(obj).next().val();
        var in_id = $(obj).next().next().val();
        var stock_old = $(obj).next().next().next().val();
        var dialog = art.dialog({title: '单个SKU盘点', lock: true});
        dialog.content('<p>数据查询中,请稍后...<p>');
        $.get("<?php echo URL::base(true)?>checkstock/updateSingle",
            {"sku": sku, "in_id": in_id, "stock_old": stock_old, 'num': num},
            function (view) {
                var view = jQuery.parseJSON(view);
                dialog.content(view.view);
            });
    }

    //下载
    $("#down").click(function () {
        window.location.href = "<?php echo URL::base()?>checkstock/spare?limit=5000&";
    });

    $("#search_down").click(function () {
        var storage1 = $("input[name='storage1']").val();
        var storage2 = $("input[name='storage2']").val();
        var storage = $("input[name='storage']").val();
        var status = $("#status_id").val();
        var sku = $("input[name='sku']").val();
        var sort = $("select[name='sort']").val();
        var order = $("select[name='order']").val();
        var start_time = $("input[name='start_time']").val();
        var source = $("#source").val();
        var uri = 'sku=' + sku + '&status=' + status + '&sort=' + sort + '&order=' + order+ '&source=' + source + '&start_time=' + start_time + '&storage1=' + storage1 + '&storage2=' + storage2 + '&storage=' + storage;

        window.location.href = "<?php echo URL::base()?>checkstock/spare?down=1&" + uri;
    });


    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符

        obj.value = obj.value.replace(/^\./g, "");  //验证第一个字符是数字而不是.

        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.

        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    }

    $(function () {
        $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
        $("#start").datepicker({
        });

        $("input[name='storage1']").keyup(function () {
            $("input[name='storage2']").val($(this).val());
        })
        $("input[name='storage1']").blur(function () {
            if ($(this).val().length < 4) {
                var len = 4 - $(this).val().length;
                var str = new Array(len + 1).join("0");
                $(this).val($(this).val() + str);
                $("input[name='storage2']").val($(this).val());
            }

            //添加搜索功能
            if ($(this).val() == '0000') {
                if ($("input[name='storage2']").val() == '0000') {
                    $("input[name='storage']").css({"color": ""});
                    $("input[name='storage']").attr("disabled", false);
                } else {
                    $("input[name='storage']").css({"color": "#888"});
                    $("input[name='storage']").attr("disabled", true);
                }
            } else {
                $("input[name='storage']").css({"color": "#888"});
                $("input[name='storage']").attr("disabled", true);
            }
        });
        $("input[name='storage2']").blur(function () {
            if ($(this).val().length < 4) {
                var len = 4 - $(this).val().length;
                var str = new Array(len + 1).join("0");
                $(this).val($(this).val() + str);
            }

            //添加搜索功能
            if ($(this).val() == '0000') {
                if ($("input[name='storage_position1']").val() == '0000') {
                    $("input[name='storage']").css({"color": ""});
                    $("input[name='storage']").attr("disabled", false);
                } else {
                    $("input[name='storage']").css({"color": "#888"});
                    $("input[name='storage']").attr("disabled", true);
                }
            } else {
                $("input[name='storage']").css({"color": "#888"});
                $("input[name='storage']").attr("disabled", true);
            }
        });
        //上传表格
        $(".upSuppForm").Validform({
            tiptype: 2,
            postonce: true
        });

        //添加模糊搜索
        $("input[name='storage']").keyup(function () {
            if ($(this).val() == '') {
                $("input[name='storage1']").attr("disabled", false);
                $("input[name='storage2']").attr("disabled", false);
            } else {
                if ($(this).val() != '库位模糊搜索') {
                    $("input[name='storage1']").css({"color": "#888"});
                    $("input[name='storage2']").css({"color": "#888"});
                    $("input[name='storage1']").attr("disabled", true);
                    $("input[name='storage2']").attr("disabled", true);
                } else {
                    $("input[name='storage1']").attr("disabled", false);
                    $("input[name='storage2']").attr("disabled", false);
                }
            }
        });
        $("#reset_").click(function () {
            $("input[name='storage1']").attr("disabled", false);
            $("input[name='storage2']").attr("disabled", false);
            $("input[name='storage']").attr("disabled", false);
        });
    })
</script>